// packageJ/yzSupplyLease/index.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    city: "请选择区域",
    region_id: "",
    rotation: [],
    goodData: null,
    imgheight: 0,
    LastHeight: 0,

    page: 1, //分页数，当前页数
    isLoadMore: true, //判断是否要加载更多的标志
    total_page: 0 //总页数
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if (wx.getStorageSync('yzSupplyArea')) {
      this.setData({
        city: wx.getStorageSync('yzSupplyArea').area,
        region_id: wx.getStorageSync('yzSupplyArea').region_id
      })
    } else {
      if (options.area) {
        this.setData({
          city: options.area
        })
      }
      if (options.region_id) {
        this.setData({
          region_id: options.region_id
        })
      }
    }
    this.getRotation();
    wx.setNavigationBarTitle({
      title: '租赁',
    })
    this.getData();

  },
  toUrl(e) {
    let urls = e.currentTarget.dataset.item;
    if(urls){
      wx.navigateTo({
        url: urls,
        fail: () => {
          wx.reLaunch({
            url: urls,
            fail:()=>{
              app.tips('链接设置错误')
            }
          })
        }
      })
    }
  },
  toLocal() {
    wx.navigateTo({
      url: '/packageJ/yzSupplyLease/yzSupplyLeaseArea/yzSupplyLeaseArea',
    })
  },
  toSearch() {
    wx.navigateTo({
      url: '/packageB/member/category/search_v2/search_v2?region_id=' + this.data.region_id +'&isYzSupple=1',
    })
  },
  getpic(e) {
    var winWid = wx.getSystemInfoSync().windowWidth; //获取当前屏幕的宽度
    var imgh = e.detail.height; //图片高度
    var imgw = e.detail.width; //图片宽度
    var swiperH = winWid * imgh / imgw + "px"; //等比设置swiper的高度。 即 屏幕宽度 / swiper高度 = 图片宽度 / 图片高度  ==》swiper高度 = 屏幕宽度 * 图片高度 / 图片宽度
    if (parseInt(swiperH) > this.data.LastHeight) {
      this.setData({
        Height: swiperH, //设置高度
      });
      console.log('sadasd', this.data.Height)
      // this.data.LastHeight = parseInt(swiperH);
    }

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  init() {
    this.setData({
      goodData: [],
      page: 1,
      isLoadMore: true,
      total_page: 0
    })
  },
  getData() {
    let urlStr = app.getNetAddresss("plugin.yz-supply-lease.api.goods.goods-list");
    urlStr += '&page='+this.data.page;
    urlStr += '&search[region]='+this.data.region_id;
    app._postNetWork({
      url: urlStr,
      success: (resdata) => {
        let res = resdata.data;
        this.setData({
          goodData: res.data.data,
          isLoadMore: true,
          total_page: res.data.last_page
        })
        if (!this.data.total_page) {
          this.data.total_page = 0;
        }
      },
    });
  },
  getRotation() {
    let urlStr = app.getNetAddresss("plugin.yz-supply-lease.api.goods.rotation-list");
    app._postNetWork({
      url: urlStr,
      data: {},
      success: (resdata) => {
        let res = resdata.data;
        this.setData({
          rotation: res.data
        })
      },
    });
  }
})